﻿$('#waitImageDiv')
    .hide()
    .ajaxStart(function () {
        $(this).show();
    })
    .ajaxStop(function () {
        $(this).hide();
    });

//////////Create
function showCreateForm() {
    $("#editItem").dialog({
        modal:true,
        title: "Create new localization item",
        height: "auto",
        width: "auto",
        show: { effect: 'slide', direction: "up" },
        hide: { effect: 'slide', direction: "up" }

    });

    $.validator.unobtrusive.parse("#createForm");
}

function successCreate(data) {
    if (data === "OK") {
        toastr.success("Localization info saved", "Save operation");
        $("#editItem").dialog("close");
        $("#filterForm").submit();
    }
    else
    {
        toastr.error(data, "Save operation");
    }
}

function errorCreate() {
    alert("Erro!");
}

////////////Edit
function showEditForm() {
    $("#editItem").dialog({
        modal:true,
        title: "Edit localization item",
        height: "auto",
        width: "auto",
        show: { effect: 'slide', direction: "up" },
        hide: { effect: 'slide', direction: "up" }
    });

    $.validator.unobtrusive.parse("#editForm");
}

function successEdit(data) {
    if (data === "OK") {
        toastr.success("Localization info saved", "Save operation");
        $("#editItem").dialog("close");
        $("#filterForm").submit();
    }
    else {
        toastr.error("Error while saving data", "Save operation");
    }
}

//////////Delete
function successDelete(data)
{
    if (data === "OK") {
        toastr.success("Localization item deleted.", "Delete operation");
        $("#filterForm").submit();
    }
    else {
        toastr.error("Error while deleting data", "Delete operation");
    }
}

////////Translate
function showTranslateForm() {
    $("#editItem").dialog({
        modal:true,
        title: "Manage translations",
        height: "auto",
        width: "auto",
        position: ["center", "center"],
        close: function () {
            $("#filterForm").submit();
        },
        show: { effect: 'slide', direction: "up" },
        hide: { effect: 'slide', direction: "up" }
    });

    $.validator.unobtrusive.parse("#editForm");
}

function successTranslate(data)
{
    if (data === "OK")
    {
        toastr.success("Translation saved.", "Save operation");
        $(".saveTranslationSuccess").show(500).hide(3000);
    }
    else
    {

    }
}

///////////////////////Create enum
function showCreateEnumForm() {
    $("#editItem").dialog({
        modal: true,
        title: "Create new Enum",
        height: "auto",
        width: "auto",
        show: { effect: 'slide', direction: "up" },
        hide: { effect: 'slide', direction: "up" }
    });

    var viewModel = new EnumManager();
    viewModel.int();
}